#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QColorDialog>
#include <QDebug>
#include <QMessageBox>
#include <QFileDialog>

MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainWindow)
{
    ui->setupUi(this);

    //标准弹窗
    m_pBtnGp = new QButtonGroup(this);
    m_pBtnGp->addButton(ui->radioButton_Info,0);
    m_pBtnGp->addButton(ui->radioButton_Question,1);
    m_pBtnGp->addButton(ui->radioButton_Warning,2);
    m_pBtnGp->addButton(ui->radioButton_Critical,3);
    m_pBtnGp->addButton(ui->radioButton_About,4);
    m_pBtnGp->addButton(ui->radioButton_AboutQt,5);


    //stackWidget index
    m_pBtnGpIndex = new QButtonGroup(this);
    m_pBtnGpIndex->addButton(ui->pushButton_stand,0);
    m_pBtnGpIndex->addButton(ui->pushButton_file,1);
    m_pBtnGpIndex->addButton(ui->pushButton_input,2);
    m_pBtnGpIndex->addButton(ui->pushButton_other,3);

    connect(m_pBtnGpIndex, QOverload<int>::of(&QButtonGroup::buttonClicked),
            [=](int id){
        ui->stackedWidget->setCurrentIndex(id);
    });
}

MainWindow::~MainWindow()
{
    delete ui;
}


void MainWindow::on_pushButton_colorDialog_clicked()
{
    QColor color = QColorDialog::getColor();
    qDebug()<<"select color:"<<color.name();
}

void MainWindow::on_pushButton_popup_clicked()
{
    QString strTitle = ui->lineEdit_title->text();
    QString strText = ui->lineEdit_text->text();
    switch (m_pBtnGp->checkedId()) {
    case 0:
        QMessageBox::information(nullptr,strTitle,strText);
        break;
    case 1:
        QMessageBox::question(nullptr,strTitle,strText);
        break;
    case 2:
        QMessageBox::warning(nullptr,strTitle,strText);
        break;
    case 3:
        QMessageBox::critical(nullptr,strTitle,strText);
        break;
    case 4:
        QMessageBox::about(nullptr,strTitle,strText);
        break;
    case 5:
        QMessageBox::aboutQt(nullptr,strTitle);
        break;
    default:
        QMessageBox::about(nullptr,strTitle,strText);
        break;
    }
}

void MainWindow::on_pushButton_chooseFile_clicked()
{
//    QString strFileName = QFileDialog::getOpenFileName(this,"选择文件",QApplication::applicationDirPath(),"文件(*.txt,*.png,*.jpg)");
//    qDebug()<<"选择文件:"<<strFileName;

//    QUrl url =  QFileDialog::getOpenFileUrl();
//    qDebug()<<"选择文件:"<<url;

//    QString strFileName = QFileDialog::getSaveFileName();
//    qDebug()<<"保存文件:"<<strFileName;

    QUrl url = QFileDialog::getSaveFileUrl();
    qDebug()<<"保存文件:"<<url;
}

void MainWindow::on_pushButton_chooseFiles_clicked()
{
    QStringList strList = QFileDialog::getOpenFileNames();
    qDebug()<<"选择文件:"<<strList;
}
